<?php
header("Content-type: text/html; charset=utf-8");
//是否允许跨域进行访问请求
header("Access-Control-Allow-Origin: *");
//用户Token-请直接在后台域名管理中复制
//$userToken = "2b88b940d17bc6b571a19c8489122376";
$userTokens = [
	"e746bc26c485a79d73120e9d09aa94be"
];
foreach ($userTokens as $key => $userToken) {
    //请求API,服务器的地址（需更改）如：spread.com =>spread.jiduba.cn
    //$callback = 'http://aoyou.com/api/upgradeTemplate?';
	$callback = 'http://aoyou.com/api/updateTemplate?';
    $callback .= 'time=' . $_POST['time'];
    $callback .= '&did=' . $_POST['did'];
    $callback .= '&token=' . md5($userToken . $_POST['time']);//.$userToken;
	$callback .= '&filename=' . $_POST['filename'];
	$callback .= '&tid=' . $_POST['term_id'];
    $contents = file_get_contents($callback);
    if (!empty($contents)) {
        $directory = $_POST['domain'] . '/' . $_POST['directory'];
        //目录不存在，创建目录和文件
        if (!is_dir($directory)) {
            mkdir(iconv("UTF-8", "GBK", $directory), 0777, true);
            //$newfile = fopen($directory . "/index.php", w);
			$newfile = fopen($directory .'/'.$_POST['filename'], w);
            fclose($newfile);
        }
        chmod($directory .'/'. $_POST['filename'], 0777);
        //把最新源码写入文件
        file_put_contents($directory.'/'.$_POST['filename'], $contents);//写入模板文件
       /*  if($_POST['filename']=='company.php'){
			$newUrl = 'http://aoyou.com/api/upgradeCompanyTemplate?';
			$newUrl .= 'time=' . $_POST['time'];
			$newUrl .= '&did=' . $_POST['did'];
			$newUrl .= '&token=' . md5($userToken . $_POST['did']);
			$companyContents = file_get_contents($newUrl);
			file_put_contents($directory . "/company.php", $companyContents);//写入审核文件
		} */
        @unlink($directory."/wxConfig.php");
        break;
    }
}

?>